//app.js
const cloudInit = require('./utils/cloud-init.js');
const Logger = require('./utils/logUtil.js');

// 获取微信实时日志实例
const wxLogger = wx.getRealtimeLogManager();

// 初始化 Logger
Logger.init({
  enableRemoteLog: true, // 是否启用远程日志
  remoteLogger: wxLogger, // 微信日志实例
});

App({
  globalData: {
    shareConfig: {}
  },
  onLaunch: function () {
    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力')
    } else {
      cloudInit.initCloud(); // 初始化云开发环境
      // 获取分享权限
      // this.getShareConfig();
    }

    // this.globalData = {}
  },
  getShareConfig: function () {
    wx.cloud.callFunction({
      name: 'getShareConfig',
      complete: res => {
        if (!res.errMsg) {
          console.error('Failed to fetch share config');
          return;
        }

        this.globalData.shareConfig = res.result;
        // 设置全局默认分享配置
        wx.setShareMenu({
          withShareTicket: true, // 是否启用转发分享
          menus: ['shareAppMessage', 'shareTimeline'] // 分享菜单项
        });

        // 设置默认分享信息
        wx.setShareAppMessage(this.globalData.shareConfig.shareAppMessage);
        wx.setShareTimeline(this.globalData.shareConfig.shareTimeline);
      }
    });
  },
  // goPath: function () {
  //   wx.onAppRoute((route) => {
  //     const pages = getCurrentPages() // 获取加载的页面
  //     const view = pages[pages.length - 1] // 当前页面对象
  //     const {
  //       share,
  //       qrCode,
  //       qrCodeStatus,
  //       effective,
  //       qrParams,
  //       geographicLocation,
  //       code
  //     } = this.globalData
  //     const sharedUserId = wx.getStorageSync('PRIVATE_USER_INFO').userId;
  //     // 页面不存在
  //     if (!view) return false
  //     view.onShareAppMessage = (res) => {
  //       console.log(route.path, 'route.path');
  //       console.log(res, 'res');
  //       switch (route.path) {
  //         case "pkgAllPlace/indent_operation/indent.operation":

  //       }
  //     }
  //   })
  // },
})